home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: howland.reston.ans.net!torn!sq!msb
- From: msb@sq.com (Mark Brader)
- Subject: Re: Newbie Questions
- Message-ID: <1996Mar24.204332.14841@sq.com>
- Organization: SoftQuad Inc., Toronto, Canada
- References: <4irpc1$b8u@GRAPEVINE.LCS.MIT.EDU> <4isgta$7cr@newsbf02.news.aol.com> <827628456snz@genesis.demon.co.uk> <3154C7FA.B38@iadfw.net>
- Date: Sun, 24 Mar 1996 20:43:32 GMT
-
- MVaccaro1:
- > > > printf( "Sizeof s1 %d\n Sizeof s2 %d\n", sizeof s1, sizeof s2 );
-
- Lawrence Kirby:
- > > Anything can happen since sizeof doesn't return an int value, it returns
- > > a value with some implementation specific unsigned type (size_t).
-
- Larry Weiss:
- > Since printf() is a member of the standard library (with unambiguous
- > semantics) couldn't the implementation be required to issue a diagnostic
- > if a mismatch were attempted?
-
- The standard could have required this, but it also could have required
- diagnostics for array bounds violations, arithmetic exceptions, and all
- sorts of other things that now cause undefined behavior. Instead, the
- standard-writers chose to avoid requiring most such diagnostics, leaving
- them instead as quality-of-implementation matters.
-
- Larry may be thinking that the necessary checking could easily be done at
- compile time. This is true only if the format argument is a string literal
- (or other constant string); in general, the check is a run-time operation.
- Internally, the compiler would probably turn
-
- printf (make_a_format(), sizeof s1, sizeof s2);
-
- into something like:
-
- {
- char *_fmt = make_a_format();
- _check_printf_format (_fmt, _UNSIGNED_INT, _UNSIGNED_INT, _END);
- printf (_fmt, sizeof s1, sizeof s2);
- }
-
- > If so, would the Standard need to say so explicitly?
-
- In effect. It would do so by putting a statement such as "The arguments
- following the format shall correspond to the conversion specifications
- in the format, as detailed below." into a Constraints section in 7.9.6.1.
- Making it a Constraint is what forces the diagnostic.
-
- Nothing in the standard ever forces a diagnostic to say something useful.
- The "ed" mode of error reporting, where any error is reported as "?", is
- permitted. Better error reporting is a quality-of-implementation issue.
-
- Conversely, nothing in the standard ever *forbids* a diagnostic, no
- matter whether undefined behavior exists or not. A compiler is allowed
- to diagnose *every* program with "?". But it wouldn't find many buyers.
- In particular, a compiler is allowed to diagnose the situations that
- Larry is asking about, and I hear there are some that do.
-
- > The information is clearly available to the implementation to support an
- > unambiguous diagnostic.
-
- Yes, but as noted above, it may require some work to do it, and the
- standard is reluctant to force implementations to do that sort of work.
- --
- Mark Brader, msb@sq.com "Ask not for whom the compiler waits;
- SoftQuad Inc., Toronto it waits for thee." -- Henry Spencer
-
- My text in this article is in the public domain.
-